<%@ page import="top.fyxxxx.dbdesign.data.Course" %>
<%@ page import="top.fyxxxx.dbdesign.util.CourseManager" %>
<%@ page import="top.fyxxxx.dbdesign.util.Manager" %>
<%@ page import="java.util.List" %>
<%@ page import="top.fyxxxx.dbdesign.util.TaskManager" %>
<%@ page import="java.util.ArrayList" %>
<%@ page import="top.fyxxxx.dbdesign.dao.DBoperate" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ page isELIgnored="false" %>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>布置签到任务</title>
    <link rel="stylesheet" type="text/css" href="assignments.css">
</head>
<body >
<%
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    CourseManager courseManager= Manager.courseManager();
    TaskManager taskManager=Manager.taskManager();
    DBoperate dBoperate=DBoperate.getInstance();
    //long uid=1590064934429L;
    //session.setAttribute("uid",uid);
    if(session.getAttribute("uid")==null)request.getRequestDispatcher("/index.jsp").forward(request,response);
    long uid=(Long) session.getAttribute("uid");
    long sid=0;
    if(request.getParameter("sid")!=null)sid=Long.parseLong(request.getParameter("sid"));
    List<String> times=new ArrayList<String>();
    for (int i=1;i<=10;i++)times.add("");
    if (sid!=0){
        times=taskManager.getTimes(sid);
        for(int i=0;i<times.size();i++) {
            times.set(i,"value='"+times.get(i)+"'");
        }

    }
    for(String t:times){
        System.out.println("----"+t);
    }
%>
<div id="content">
    <div class="login-header">
        <img src="Image/logo.png">
    </div>
    <%
        String mes[]={"参数残缺","权限不足","终止时间小于起始时间","创建成功","格式错误","?"};
        int messageNum=5;
        if(request.getParameter("Message")!=null)
            messageNum=Integer.parseInt(request.getParameter("Message"));
        String message=mes[messageNum];
        System.out.println(request.getParameter("cid"));
        long cid=Long.parseLong(request.getParameter("cid"));
    %>
    <form action="TaskServlet" method="post">
        <input type="hidden" name="cid" value="<%=cid%>">
        <input type="hidden" name="sid" value=<%=sid%>>
        <div class="login-input-box" style="width: 340px" >
            课程<br>
            <%=dBoperate.getCourse(cid).getName()%>
            <br>
        </div>
        <div class="login-input-box" >
            签到日期<br>
            <input  type="text" name="StartTimeYear"
                    placeholder="2020-2100" <%=times.get(0)%>
            >
            年
            <input type="text" name="StartTimeMonth"
                   placeholder="1-12" <%=times.get(1)%>
            >
            月
            <input type="text" name="StartTimeDate"
                   placeholder="1-31" <%=times.get(2)%>
            >
            日
            <br>
        </div>

        <div class="login-input-box">
            时间段<br>
            <input  type="text" name="StartTimeHour"
                    placeholder="1-24" <%=times.get(3)%>
            >
            时
            <input  type="text" name="StartTimeMinute"
                    placeholder="0-59" <%=times.get(4)%>
            >
            分 到
            <br>

            <input  type="text" name="EndTimeHour"
                    placeholder="1-24"  <%=times.get(5)%>
            >
            时
            <input  type="text" name="EndTimeMinute"
                    placeholder="0-59"  <%=times.get(6)%>
            >
            分
        </div>
        <div class="login-button-box">
            <button   type="submit" value="提交"><%=(sid==0)?"":"重新"%>发布</button>
        </div>
    </form>
</div>
<div style="text-align: center"><p class="title"><a href="teacherMainPage.jsp">返回首页</a></p></div>
<%
if(message!=null&&!message.equals("?")){
%>
<script type="text/javascript" language="javascript">
    alert("<%=message%>");
</script>
<%
    }
%>
</body>
</html>
